
<template>
	<div>
		<InputOutputDefine
			:versionId="props.id"
			:stepCode="props.nodeId"
			:topFlag="false"
			:resource="props.frontFile"
			:outputFlag="false"
			:inputFlag="true"
		>
		</InputOutputDefine>
		<a-row>
			<a-col span="12">
				<ParamDefine
					:params="input"
					:isViewBasicFieldFlag="false"
					:isViewArrayFlag="false"
					:isAddColumnFlag="false"
					:isActionColumnFlag="false"
					:isUpdateColumnFlag="false"
					:jsonEditorFlag="false"
					:isRemoveColumnFlag="false"
					:isAddChildrenColumnFlag="false"
					:isMappingColumnFlag="false"
					ref="left"
				>
				</ParamDefine>
			</a-col>
			<a-col span="12">
				<a-row class="mb-2">
					<a-col span="24">
						<a-tag>排除:</a-tag>
						<a-input
							style="width: 300px"
							v-if="props.componentConfig?.config"
							v-model:value="props.componentConfig.config.excludeJsonPath"
							placeholder="jsonPath"
							@pressEnter="split"
						></a-input>
					</a-col>
				</a-row>
				<a-row>
					<a-col span="24">
						<ParamDefine
							v-if="props.componentConfig?.config"
							:params="props.componentConfig?.config?.output"
							:isViewBasicFieldFlag="false"
							:isViewArrayFlag="false"
							:isAddColumnFlag="false"
							:isActionColumnFlag="false"
							:isUpdateColumnFlag="false"
							:jsonEditorFlag="false"
							:isRemoveColumnFlag="false"
							:isAddChildrenColumnFlag="false"
							:isMappingColumnFlag="false"
							ref="right"
						>
						</ParamDefine>
					</a-col>
				</a-row>
			</a-col>
		</a-row>
	</div>
</template>

<script setup>
import { onMounted, ref, watch, toRaw, inject, getCurrentInstance } from 'vue'
import processVersionContentApi from '@/api/process/processVersionContentApi'
import ParamDefine from '@/views/restapi/ParamDefine.vue'
const props = defineProps(['componentConfig', 'nodeId', 'id', 'frontFile'])
import { mergeStepConfigToFrontFile } from '@/utils'

const left = ref()

const input = ref({
	params: [],
	basicTypeFlag: false,
	isArrayFlag: false
})

const defaultConfig = () => {
	return {
		config: {
			excludeJsonPath: null,
			output: {
				params: [],
				basicTypeFlag: false,
				isArrayFlag: false
			}
		}
	}
}
onMounted(async () => {
	if (!hasProperties(props.componentConfig)) {
		const c = defaultConfig()
		props.componentConfig.config = c.config
	}
	await queryInput()
	split()
})

const hasProperties = (obj) => {
	if (!obj) {
		return false
	}

	return JSON.stringify(obj) != '{}'
}

const queryInput = async () => {
	const c = await getInputDefine()
	const cb = left.value.repairJson(c)
	input.value = cb
}
const getInputDefine = async () => {
	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentInputDefine({
		id: props.id,
		frontFile: props.frontFile,
		stepCode: props.nodeId
	})
	return read
}

const split = async () => {
	const c = await getOutputDefine()
	const cb = left.value.repairJson(c)
	props.componentConfig.config.output = cb
}

const getResource = () => {
	let frontFile = mergeStepConfigToFrontFile(props.frontFile, props.nodeId, props.componentConfig)
	return frontFile
}

const getOutputDefine = async () => {
	let resource = getResource()
	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentOutputDefine({
		id: props.id,
		frontFile: resource,
		stepCode: props.nodeId
	})
	return read
}
</script>

<style scoped></style>
